package cn.xawl.gulimall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.xawl.gulimall.product.vo.spuvo.SpuInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.xawl.gulimall.product.entity.SpuInfoEntity;
import cn.xawl.gulimall.product.service.SpuInfoService;
import cn.xawl.common.utils.PageUtils;
import cn.xawl.common.utils.R;



/**
 * spu信息
 *
 * @author lh
 * @email lhm49869999@163.com
 * @date 2020-06-17 14:15:22
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * /product/spuinfo/{spuId}/up
     * 商品上架
     */
    @PostMapping("/{spuId}/up")
    public R up(@PathVariable Long spuId) {
        spuInfoService.spuUp(spuId);

        return R.ok();
    }

    /**
     * spu检索
     * /product/spuinfo/list
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = spuInfoService.queryPageByCondition(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 新增商品
     * /product/spuinfo/saveSkuFullReduction
     */
    @PostMapping("/save")
        public R save(@RequestBody SpuInfoVo spuInfoVo){
		spuInfoService.saveSpu(spuInfoVo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
        public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
        public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
